﻿using DongFangGuoKai.WMSPlatform.Commn.ApiResultModule;
using Microsoft.AspNetCore.Mvc;

namespace DongFangGuoKai.WMSPlatform.WebApi.Controllers
{
    /// <summary>
    /// 自定义BaseController，扩展控制器
    /// </summary>
    public class BaseController : ControllerBase
    {
        public BaseController()
        {

        }

        #region Respons 
        protected async Task<IActionResult> SuccessAsync<TRespons>(TRespons respons, string msg = "OK") where TRespons : class
        {
            ApiDataResult<TRespons> res = new ApiDataResult<TRespons>()
            {
                Code = 200,
                Data = respons,
                Msg = msg,
                Success = true

            };
            return await Task.FromResult(new JsonResult(res));
        }
        protected async Task<IActionResult> SuccessAsync(string msg = "OK")
        {
            ApiBaseResult res = new ApiBaseResult()
            {
                Code = 200,
                Msg = msg,
                Success = true
            };
            return await Task.FromResult(new JsonResult(res));
        }

        protected IActionResult Success<TRespons>(TRespons respons, string msg = "OK") where TRespons : class
        {
            ApiDataResult<TRespons> res = new ApiDataResult<TRespons>()
            {
                Code = 200,
                Data = respons,
                Msg = msg,
                Success = true

            };
            return new JsonResult(res);
        }
        protected IActionResult Success<TRespons>(TRespons respons, int count, string msg = "OK") where TRespons : class
        {
            ApiDataResult<TRespons> res = new ApiDataResult<TRespons>()
            {
                Code = 200,
                Data = respons,
                Msg = msg,
                Success = true,
                Count = count

            };
            return new JsonResult(res);
        }
        protected IActionResult Success(string msg = "OK")
        {
            ApiBaseResult res = new ApiBaseResult()
            {
                Code = 200,
                Msg = msg,
                Success = true
            };
            return new JsonResult(res);
        }

        protected IActionResult Failed(string msg = "Failed", int code = 500)
        {
            ApiBaseResult res = new ApiBaseResult()
            {
                Code = code,
                Msg = msg,
                Success = false

            };
            return new JsonResult(res);
        }
        protected async Task<IActionResult> FailedAsync(string msg = "Failed", int code = 500)
        {
            ApiBaseResult res = new ApiBaseResult()
            {
                Code = code,
                Msg = msg,
                Success = false

            };
            return await Task.FromResult(new JsonResult(res));
        }

        protected async Task<IActionResult> ResultAsync(string msg, int code)
        {
            var res = new ApiBaseResult()
            {
                Code = code,
                Msg = msg
            };
            return await Task.FromResult(new JsonResult(res));
        }
        protected async Task<IActionResult> ResultAsync<TRespons>(TRespons tRespons)
        {
            return await Task.FromResult(new JsonResult(tRespons));
        }

        protected async Task<TRespons> ResponsAsync<TRespons>(TRespons tRespons)
        {
            return await Task.FromResult(tRespons);
        }

        protected TRespons Respons<TRespons>(TRespons respons)
        {
            return respons;
        }
        #endregion

    }
}
